const { NODE_ENV, CDN_URL } = process.env;

const cdn = {
  // 开发环境
  dev: {
    css: [],
    js: [
      `./config/shieldConfig.js?v=${new Date().getTime()}`,
      `./cache.js?v=${new Date().getTime()}`
    ]
  },
  // 生产环境
  build: {
    css: [],
    js: [
      `./config/shieldConfig.js?v=${new Date().getTime()}`,
      `./cache.js?v=${new Date().getTime()}`,
      `${CDN_URL}/vue/2.6.14/vue.runtime.min.js`,
      `${CDN_URL}/vue-router/3.2.0/vue-router.min.js`,
      `${CDN_URL}/vuex/3.5.1/vuex.min.js`,
      `${CDN_URL}/axios/0.21.0/axios.min.js`
    ]
  }
};

module.exports = (config) => {
  // cdn
  if (NODE_ENV === "production") {
    config.externals({
      vue: "Vue",
      vuex: "Vuex",
      axios: "axios",
      "vue-router": "VueRouter"
    });
  }
  // 如果是多页配置。这一块要修改
  config.plugin("html-index").tap((args) => {
    args[0].CDN = NODE_ENV === "production" ? cdn.build : cdn.dev;
    return args;
  });
};
